import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:klfz_flutter/Home/RecommendPage.dart';
import 'package:klfz_flutter/Statics/normal.dart';
import 'package:get/get.dart';

class HomeWidget extends StatefulWidget {
  const HomeWidget({Key? key}) : super(key: key);
  @override
  _HomeWidgetState createState() => _HomeWidgetState();
}

class _HomeWidgetState extends State<HomeWidget> with SingleTickerProviderStateMixin {

  late TabController _tabController;
  @override
  void initState() {
    _tabController = TabController(length: 6, vsync: this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: navicatBar(context),
        // leading: IconButton (icon:Icon(Icons.search), tooltip:'搜索',onPressed:(){},),
        actions: [
          IconButton (icon:Icon(Icons.history, color: Colors.white,), onPressed:(){},),
          IconButton (icon:Icon(Icons.grid_view, color: Colors.white,), onPressed: gotoScreenPage,),
        ],
        bottom: TabBar(
          isScrollable: true,
          indicatorColor: Colors.white,
          indicatorWeight: 4,
          indicatorPadding: EdgeInsets.zero,
          labelPadding: EdgeInsets.only(bottom: 2, left: 20,  right: 20),
          automaticIndicatorColorAdjustment: true,
          controller: _tabController,
          labelStyle: TextStyle(fontSize: 16),
          unselectedLabelStyle: TextStyle(fontSize: 12),
          tabs: List.generate(NormalStatis.tabStrs.length, (index) => Text(NormalStatis.tabStrs[index]))
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: [
          RecommendPage(),
          RecommendPage(),
          RecommendPage(),
          RecommendPage(),
          RecommendPage(),
          RecommendPage(),
        ]
      ),
    );
  }

  Widget navicatBar(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    return Container(
      height: 30,
      // width: size.width * 0.6,
      padding: EdgeInsets.only(left: 15, top: 2, bottom: 3),
      decoration: BoxDecoration(
        border: Border.all(color: Colors.white, width: 1),
        borderRadius: BorderRadius.all(Radius.circular(15)),
      ),
      child: Row(
       children: [
         // Icon(Icons.search, size: 20,),
         Text("🔍 搜索更多影视", style: TextStyle(fontSize: 12, color: Colors.white),)
       ],
     ),
    );
  }

  void gotoScreenPage() {
    Get.toNamed("/screen");
  }

}
